<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>构造函数里面的this</title>
</head>

<body>

  <script>

    function Person(name) {
      this.name = name
      // console.log(this); // new 运算出来的实例化对象

      this.say = function () {
        console.log("say()中的this:", this);// new 运算出来的实例化对象

        window.setTimeout(function () {
          console.log("定时器里面的this:", this); // window
        }, 0);

        setTimeout(
          // 箭头函数中的this，指向创建箭头函数的上下文对象中的this.
          () => {
            console.log("定时器里面的this:", this); // new 运算出来的实例化对象
          }
          , 1);

        let that = this;
        window.setTimeout(function () {
          console.log("定时器里面的this:", that); // that指向 new 运算出来的实例化对象
        }, 0);
      }
    }

    let t = new Person('唐辅运')

    t.say()



  </script>

</body>

</html>